/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.hwr.nbaplan.shared.model;

import java.io.Serializable;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author flo
 */
@Entity
@Table(name = "t_vorlesung", catalog = "nbaplan", schema = "")
@SequenceGenerator(name="vorlesungs_id", sequenceName="vorlesung_seq", initialValue=1, allocationSize=1)
@NamedQueries({
    @NamedQuery(name = "Vorlesung.findAll", query = "SELECT v FROM Vorlesung v"),
    @NamedQuery(name = "Vorlesung.findById", query = "SELECT v FROM Vorlesung v WHERE v.id = :id"),
    @NamedQuery(name = "Vorlesung.findByName", query = "SELECT v FROM Vorlesung v WHERE v.name = :name"),
    @NamedQuery(name = "Vorlesung.findByOrt", query = "SELECT v FROM Vorlesung v WHERE v.ort = :ort"),
    @NamedQuery(name = "Vorlesung.findByDeleted", query = "SELECT v FROM Vorlesung v WHERE v.deleted = :deleted"),
    @NamedQuery(name = "Vorlesung.findByDeleteddate", query = "SELECT v FROM Vorlesung v WHERE v.deleteddate = :deleteddate"),
    @NamedQuery(name = "Vorlesung.findByAdded", query = "SELECT v FROM Vorlesung v WHERE v.added = :added"),
    @NamedQuery(name = "Vorlesung.findByDataload", query = "SELECT v FROM Vorlesung v WHERE v.dataload = :dataload"),
    @NamedQuery(name = "Vorlesung.findByBeginn", query = "SELECT v FROM Vorlesung v WHERE v.beginn = :beginn"),
    @NamedQuery(name = "Vorlesung.findByEnde", query = "SELECT v FROM Vorlesung v WHERE v.ende = :ende")})
public class Vorlesung implements Serializable {
    
  
    private static final long serialVersionUID = 1L;
    @Id
    //@GeneratedValue(strategy = GenerationType.AUTO)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="vorlesungs_id")
    @Basic(optional = false)
    @Column(name = "ID",  updatable = false,nullable = false)
    private Long id;
    @Basic(optional = false)
    @Column(name = "name", nullable = false, length = 255)
    private String name;
    @Column(name = "ort", length = 255)
    private String ort;
    @Column(name = "beschreibung", length = 65535)
    private String beschreibung;
    @Basic(optional = false)
    @Column(name = "deleted")
    private short deleted;
    @Column(name = "deleteddate")
    @Temporal(value = TemporalType.DATE)
    private Calendar  deleteddate;
    @Basic(optional = false)
    @Column(name = "added", nullable = false)
    private short added;
    @Basic(optional = false)
    @Column(name = "dataload", nullable = false)
    @Temporal(value = TemporalType.DATE)
    private Calendar  dataload;
    @Basic(optional = false)
    @Column(name = "beginn", nullable = false)
    @Temporal(value = TemporalType.TIMESTAMP)
    private Calendar  beginn;
    @Basic(optional = false)
    @Column(name = "ende", nullable = false)
    @Temporal(value = TemporalType.TIMESTAMP)
    private Calendar  ende;
    @JoinColumn(name = "f_modul", referencedColumnName = "ID", nullable = false)
    @ManyToOne(optional = false)
    private Modul fModul;
    @Column(name = "professor", length = 100)
    private String professor;
    //@Column(name = "addid")
    //private Long addid;
    @Transient
    private boolean gefunden;
    /**
     *
     */
    public Vorlesung() {
    }

    /**
     *
     * @param id
     */
    public Vorlesung(Long id) {
        this.id = id;
    }

    /**
     *
     * @param id
     * @param name
     * @param deleted
     * @param added
     * @param dataload
     * @param beginn
     * @param ende
     */
    public Vorlesung(Long id, String name, short deleted, short added, Calendar dataload, Calendar beginn, Calendar ende) {
        this.id = id;
        this.name = name;
        this.deleted = deleted;
        this.added = added;
        this.dataload = dataload;
        this.beginn = beginn;
        this.ende = ende;
    }
    /**
     *
     * @param name
     * @param beginn
     * @param ende
     * @param ort
     * @param beschreibung
     * @param dataload
     */
    public Vorlesung( String name, Calendar beginn, Calendar ende,String ort, String beschreibung,Calendar dataload) {
        
        this.name = name;
        this.dataload = dataload;
        this.beginn = beginn;
        this.ende = ende;
        this.ort=ort;
        this.setBeschreibung(beschreibung);
       

    }
   
    /**
     *
     * @return
     */
    public Long getId() {
        return id;
    }

    /**
     *
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     *
     * @return
     */
    public String getName() {
        return name;
    }

    /**
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     *
     * @return
     */
    public String getOrt() {
        return ort;
    }

    /**
     *
     * @param ort
     */
    public void setOrt(String ort) {
        this.ort = ort;
    }

    /**
     *
     * @return
     */
    public String getBeschreibung() {
        return beschreibung;
    }

    /**
     *
     * @param beschreibung
     */
    public void setBeschreibung(String beschreibung) {
        this.beschreibung = beschreibung;
		String[] arr=beschreibung.split("\n");
		for(String atr: arr){
			if(atr.startsWith("Dozent:")){
				this.setProfessor(atr.split(":")[1]);
			}
			
		}
    }
    /**
     *
     * @return
     */
    public boolean isDeleted(){
        if(deleted==1)
            return true;
        return false;
    }
    /**
     *
     * @return
     */
    public short getDeleted() {
       
        return deleted;
    }

    /**
     *
     * @param deleted
     */
    public void setDeleted(short deleted) {
        this.deleted = deleted;
        this.setDeleteddate(new GregorianCalendar());
    }

    /**
     *
     * @return
     */
    public Calendar getDeleteddate() {
        return deleteddate;
    }

    /**
     *
     * @param deleteddate
     */
    public void setDeleteddate(Calendar deleteddate) {
        this.deleteddate = deleteddate;
    }

    /**
     *
     * @return
     */
    public short getAdded() {
        return added;
    }

    /**
     *
     * @param added
     */
    public void setAdded(short added) {
        this.added = added;
    }

    /**
     *
     * @return
     */
    public Calendar getDataload() {
        return dataload;
    }

    /**
     *
     * @param dataload
     */
    public void setDataload(Calendar dataload) {
        this.dataload = dataload;
    }

    /**
     *
     * @return
     */
    public Calendar getBeginn() {
        return beginn;
    }

    /**
     *
     * @param beginn
     */
    public void setBeginn(Calendar beginn) {
        this.beginn = beginn;
    }

    /**
     *
     * @return
     */
    public Calendar getEnde() {
        return ende;
    }

    /**
     *
     * @param ende
     */
    public void setEnde(Calendar ende) {
        this.ende = ende;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Vorlesung)) {
            return false;
        }
        Vorlesung other = (Vorlesung) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }
    /**
     *
     * @param object
     * @return
     */
    public boolean equalsNameBeginnEnde(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Vorlesung)) {
            return false;
        }
        Vorlesung other = (Vorlesung) object;
        if ((this.name != null && !this.name.equals(other.name) ) || (this.beginn != null && !this.beginn.equals(other.beginn))|| (this.ende != null && !this.ende.equals(other.ende))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "de.hwr.nbaplan.shared.model.Vorlesung[id=" + id + "]";
    }

    /**
     *
     * @return
     */
    public String getProfessor() {
        return professor;
    }

    /**
     *
     * @param professor
     */
    public void setProfessor(String professor) {
        this.professor = professor;
    }

    /**
     *
     * @return
     */
    public Modul getFModul() {
        return fModul;
    }

    /**
     *
     * @param fModul
     */
    public void setFModul(Modul fModul) {
        this.fModul = fModul;
    }

   

    /**
     * @return the gefunden
     */
    public boolean isGefunden() {
        return gefunden;
    }

    /**
     * @param gefunden the gefunden to set
     */
    public void setGefunden(boolean gefunden) {
        this.gefunden = gefunden;
    }

    

}
